//
//  MKUserModel.m
//  Teleport
//
//  Created by xtjun on 2020/5/18.
//  Copyright © 2020 xxt. All rights reserved.
//

#import "TJUserInfo.h"


#define PATH [@"account.arc" tj_documentsPath]

static id instance = nil;


@implementation TJUserInfo

MJCodingImplementation


+ (instancetype)shareUserInfoModel {
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        instance = [[TJUserInfo alloc] init];
    });
    return instance;
}

+ (NSDictionary *)mj_replacedKeyFromPropertyName {
    return @{@"userId" : @"id"};
}

- (NSString *)token {
    return _token ?: @"";
}

-(NSString *)userId {
    return _userId ?: @"";
}
/**保存到本地 */
- (BOOL)saveInfo {
    return [NSKeyedArchiver archiveRootObject:self toFile:PATH];
}

+ (TJUserInfo *)readInfo {
    TJUserInfo *userInfo = [NSKeyedUnarchiver unarchiveObjectWithFile:PATH];
    if (!userInfo) userInfo = [TJUserInfo shareUserInfoModel];
    return userInfo;
}

+ (BOOL)deleteInfo {
    [Tools removeAvatarImage];
    NSFileManager *defaultManager = [NSFileManager defaultManager];
    if ([defaultManager isDeletableFileAtPath:PATH]) {
        return [defaultManager removeItemAtPath:PATH error:nil];
    }
    return NO;
}

- (void)updateUserInfoWithInfoDict:(NSDictionary *)infoDict {
  
    
    self.payAliay = infoDict[@"payAliay"];
    self.aliayName = infoDict[@"aliayName"];
    
    self.payWechat = infoDict[@"payWechat"];
    self.wechatName = infoDict[@"wechatName"];
    
    self.bankCard = infoDict[@"bankCard"];
    self.bankName = infoDict[@"bankName"];
    self.bankAddress = infoDict[@"bankAddress"];
   
    
    self.headLink = infoDict[@"headLink"];
    self.cardState = infoDict[@"cardState"];
    self.nickName = infoDict[@"nickName"];
    self.uname = infoDict[@"uname"];
    self.cardNo = infoDict[@"cardNo"];
    self.areaCode = infoDict[@"areaCode"];
    self.uuid = infoDict[@"uuid"];
    
    
    
    self.mail = infoDict[@"mail"];
    self.storeState = infoDict[@"storeState"];
    self.storeName = infoDict[@"storeName"];
    
    self.payPassword = infoDict[@"payPassword"];
    
    //可用资产
    
    [self saveInfo];
}

@end
